﻿@{
}
@model Mango.Manager.ViewModels.PostsViewModel

<table class="table">
    <tbody>
        <tr>
            <td></td>
        </tr>
    </tbody>
</table>
<table class="table  table-sm table-hover table-list table-bordered">
    <thead>
        <tr>
            <th>Id</th>
            <th>标题</th>
            <th>发布用户</th>
            <th>发布时间</th>
            <th>最后更新时间</th>
            <th>浏览数</th>
            <th>+1数</th>
            <th>评论数</th>
            <th>是否显示</th>
            <th>是否允许回复</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model.ListData)
        {
        <tr>
            <td>
                @item.PostsId
            </td>
            <td>
                @item.Title
            </td>
            <td>
                @item.NickName
            </td>
            <td>
                @item.PostDate
            </td>
            <td>
                @item.LastDate
            </td>
            <td>
                @item.ReadCount
            </td>
            <td>
                @item.PlusCount
            </td>
            <td>
                @item.AnswerCount
            </td>
            <td>
                @(item.IsShow ? "是" : "否")
            </td>
            <td>
                @(item.IsReply ? "是" : "否")
            </td>
            <td>
                <a href="javascript:SetShow(@item.PostsId, @(item.IsShow?"false":"true"));" class="del"> @(item.IsShow ? "设为隐藏" : "设为显示")</a>
                <a href="javascript:SetReply(@item.PostsId, @(item.IsReply?"false":"true"));" class="del"> @(item.IsReply ? "设为禁止" : "设为允许")</a>
            </td>
        </tr>
        }
    </tbody>
</table>
<div class="row">
    <div class="col-12">
        <ul class="pagination  justify-content-center">
            @Html.MPager(ViewContext.HttpContext.Request, Model.TotalCount)
        </ul>
    </div>
</div>
<script type="text/javascript">
    function SetShow(postsId, isShow) {
        $.ajax({
            type: 'post',
            url: '/Posts/SetShow',
            data: 'postsId=' + postsId + '&isShow=' + isShow,
            success: function (res) { 
                if (res) {
                    window.location.href = window.location.href;
                }
            }
        });
    }
    function SetReply(postsId, isReply) {
        $.ajax({
            type: 'post',
            url: '/Posts/SetReply',
            data: 'postsId=' + postsId + '&isReply=' + isReply,
            success: function (res) {
                if (res) {
                    window.location.href = window.location.href;
                }
            }
        });
    }
</script>